#pragma once

#include "LEGACYREPLACER.HPP"

/////////////////////////////////////////////////////////////////////////////
#ifndef DXUTIL_H
#define DXUTIL_H
#ifndef SAFE_DELETE
 #define SAFE_DELETE(p)                                                     \
         {if (p)                                                            \
          {                                                                 \
           delete (p);                                                      \
           (p) = nullptr;                                                      \
          }                                                                 \
         }
 #endif    
#ifndef SAFE_DELETE_ARRAY
 #define SAFE_DELETE_ARRAY(p)                                               \
         {                                                                  \
          if (p)                                                            \
          {                                                                 \
           delete[] (p);                                                    \
           (p) = nullptr;                                                      \
          }                                                                 \
         }
 #endif    
#ifndef SAFE_RELEASE
 #define SAFE_RELEASE(p)                                                    \
         {                                                                  \
          if(p)                                                             \
          {                                                                 \
           (p)->Release();                                                  \
           (p) = nullptr;                                                      \
          }                                                                 \
         }
 #endif
#if defined(DEBUG) | defined(_DEBUG)
  #define DXTRACE DXUtil_Trace
#else
  #define DXTRACE sizeof
#endif
/////////////////////////////////////////////////////////////////////////////
enum TIMER_COMMAND 
 {
  TIMER_RESET,
  TIMER_START,
  TIMER_STOP,
  TIMER_ADVANCE,
  TIMER_GETABSOLUTETIME,
  TIMER_GETAPPTIME,
  TIMER_GETELAPSEDTIME
};
/////////////////////////////////////////////////////////////////////////////
enum ArrayListType
{
 AL_VALUE,                                      // entry data is copied
                                                // into the list 
 AL_REFERENCE,                                  // entry pointers are
};                                              // copied into the list
/////////////////////////////////////////////////////////////////////////////
FLOAT FAREXPORT CALLBACK DXUtil_Timer
                 (TIMER_COMMAND command);
HRESULT FAREXPORT
 DXUtil_ConvertAnsiStringToWideCch
        (WCHAR* wstrDestination,
         const CHAR* strSource,
         int cchDestChar);
HRESULT FAREXPORT
 DXUtil_ConvertWideStringToAnsiCch
         (CHAR* strDestination,
          const WCHAR* wstrSource,
          int cchDestChar);
HRESULT FAREXPORT
 DXUtil_ConvertGenericStringToAnsiCch
         (CHAR* strDestination,
          const TCHAR* tstrSource,
          int cchDestChar);
HRESULT FAREXPORT
 DXUtil_ConvertGenericStringToWideCch
         (WCHAR* wstrDestination,
          int iSizestrDest,
          const TCHAR* tstrSource,
          int cchDestChar);
HRESULT FAREXPORT
 DXUtil_ConvertAnsiStringToGenericCch
         (TCHAR* tstrDestination,
          const CHAR* strSource, 
          int cchDestChar);
HRESULT FAREXPORT
 DXUtil_ConvertWideStringToGenericCch
         (TCHAR* tstrDestination,
          int iSizestrDest,
          const WCHAR* wstrSource,
          int cchDestChar);
HRESULT FAREXPORT
 DXUtil_ConvertAnsiStringToWideCb
         (WCHAR* wstrDestination,
          const CHAR* strSource,
          int cbDestChar);
HRESULT FAREXPORT
 DXUtil_ConvertWideStringToAnsiCb
         (CHAR* strDestination,
          const WCHAR* wstrSource,
          int cbDestChar);
HRESULT FAREXPORT
 DXUtil_ConvertGenericStringToAnsiCb
         (CHAR* strDestination,
          const TCHAR* tstrSource,
          int cbDestChar);
HRESULT FAREXPORT
 DXUtil_ConvertGenericStringToWideCb
         (WCHAR* wstrDestination,
          int iSizestrDest,
          const TCHAR* tstrSource,
          int cbDestChar);
HRESULT FAREXPORT
 DXUtil_ConvertAnsiStringToGenericCb
         (TCHAR* tstrDestination,
          const CHAR* strSource,
          int cbDestChar);
HRESULT FAREXPORT
 DXUtil_ConvertWideStringToGenericCb
         (TCHAR* tstrDestination,
          int iSizestrDest,
          const WCHAR* wstrSource, 
          int cbDestChar);
VOID    DXUtil_Trace(TCHAR* strMsg,...);
/////////////////////////////////////////////////////////////////////////////
class CArrayList
{
protected:
    ArrayListType m_ArrayListType;
    void* m_pData;
    UINT m_BytesPerEntry;
    UINT m_NumEnt;
    UINT m_NumEntAllocated;

public:
    CArrayList(ArrayListType Type,
               UINT BytesPerEntry = 0);
    ~CArrayList(void);
    HRESULT Add(void* pEntry);
    void Remove(UINT Entry);
    void* GetPtr(UINT Entry);
    UINT Count(void)
    {
     return m_NumEnt; 
    }
    bool Contains(void* pEntryData);
    void Clear(void)
    {
     m_NumEnt = 0; 
    }
};
#define GETTIMESTAMP timeGetTime
#define _TWINCE(x) x
#endif                                          // DXUTIL_H
